#define _CRT_SECURE_NO_WARNINGS

//#include <stdio.h>
//#include <stdlib.h>
//
//int cmp_int(const void* e1,const void *e2)
//{
//	return (*(int*)e1) - (*(int*)e2);
//}
//void test1()
//{
//	int arr[10] = { 9,8,7,6,5,4,3,2,1,0 };
//	int sz = sizeof(arr) / sizeof(arr[0]);
//	qsort(arr, sz, sizeof(arr[0]), cmp_int);
//	int i = 0;
//	for (i = 0; i < sz; i++)
//	{
//		printf("%d ", arr[i]);
//	}
//}
//#include <string.h>
//
//int cmp_struct_name(const void* e1, const void* e2)
//{
//	return strcmp(((struct Peo*)e1)->name, ((struct Peo*)e2)->name);
//}
//struct Peo
//{
//	char name[10];
//	int age;
//};
//void test2()
//{
//	struct Peo p[3] = { {"wangwu",15},{"lisi",18},{"hacha",40} };
//	int sz = sizeof(p) / sizeof(p[0]);
//	qsort(p, sz, sizeof(p[0]), cmp_struct_name);
//}
//int main()
//{
//	//test1();
//	test2();
//	return 0;
//}

#include <stdio.h>
int cmp_int(const void* e1, const void* e2)
{
	return (*(int*)e1) - (*(int*)e2);
}
void Swap(char* buf1, char* buf2, int width)
{
	int i = 0;
	while (i < width)
	{
		char tmp = *buf1;
		*buf1 = *buf2;
		*buf2 = tmp;
		i++;
		buf1++;
		buf2++;
	}
}
void bubble_sort(void* base, int sz, int width, int (*cmp_int)(const void* e1, const void* e2))
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (cmp_int((char*)base + j * width, (char*)base + (j + 1) * width)>0)
			{
				int i = 0;
				char* buf1 = (char*)base + j * width;
				char* buf2 = (char*)base + (j + 1) * width;
				while (i < width)
				{
					char tmp = *buf1;
					*buf1 = *buf2;
					*buf2 = tmp;
					i++;
					buf1++;
					buf2++;
				}
			}
		}
	}
}
int main()
{
	int arr[10] = { 7,6,3,4,8,9,1,2,5,0 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr, sz, sizeof(arr[0]), cmp_int);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}
